import com.speljohan.rsbot.script.Random;
import com.speljohan.rsbot.script.wrappers.RSInterfaceChild;
import com.speljohan.rsbot.script.wrappers.RSNPC;

public class FrogCave extends Random
{

    @Override
    public String getAuthor()
    {
        return "Nightmares18";
    }

    @Override
    public double getVersion()
    {
        return 1.2;
    }

    public int[] frogIDS = {390,391,392,393,394,395,396,397,398,399,400,401,402,403};
    public RSNPC frog = null;

    @Override
    public boolean activateCondition()
    {
        return inFrogCave();
    }

    public boolean inFrogCave()
    {
        if(getNearestNPCByName("Frog Herald") != null)
            return true;
        
        for(int i = 0;i<frogIDS.length;i++)
        {
            RSNPC npc = getNearestNPCByID(frogIDS[i]); 
            if(npc != null)
            { 
                if(npc.getName().contains("null") || npc.getName() == null)
                    return true;
            }
        }
        return false;
    }

    @Override
    public int loop() {
        boolean clickedHerald = false;
                RSNPC herald = this.getNearestNPCByName("Frog Herald");
                while(canContinue())
                {
                  	clickContinue();
                    wait(random(1000,1100));
                }
                if(herald != null && !clickedHerald)
                {
                    turnToTile(herald.getLocation());
                    walkTo(herald.getLocation());
                    wait(random(1000,1100));
                    while(getMyPlayer().isMoving())
                        wait(random(1000,1100));
                    atNPC(herald,"Talk-to");
                    waitToMove(2000);
                    while(getMyPlayer().isMoving())
                        wait(random(1000,1100));
                    wait(random(1000,2000));
                    while(canContinue())
                    {
                        clickContinue();
                        wait(random(1000,1100));
                    }
                    clickedHerald = true;
                }
                    log.info("Finding Right Frog");
                    for(int i = 0;i<frogIDS.length;i++)
                    {
                        RSNPC npc = this.getNearestNPCByID(frogIDS[i]);
                        if(npc != null)
                        {
                            while(npc.isMoving())
                                wait(random(50,100));
                            if(npc.getHeight() == -68)
                            {
                                frog = npc;
                            }
                        }
                    }
               if(frog != null)
               {
                    log.info("Found Right Frog");
                    turnToTile(frog.getLocation());
                    walkTo(frog.getLocation());
                    wait(random(1000,1100));
                    while(getMyPlayer().isMoving())
                        wait(random(1000,1100));
                    atNPC(frog,"Talk-to");
                    waitToMove(2000);
                    while(getMyPlayer().isMoving())
                        wait(random(1000,1100));
                    wait(random(1000,2000));
                    while(canContinue())
                    {
                        clickContinue();
                        wait(random(1000,1100));
                    }
                    RSInterfaceChild face = this.getChildInterface(236,1);
                    if(face != null)
                        atInterface(face);
                    wait(random(1000,2000));
                    while(canContinue())
                    {
                        clickContinue();
                        wait(random(1000,1100));
                    }
			  wait(random(10000,15000));
                }
                frog = null;
            return -1;
    }
}